package cn.xy

import scala.util.parsing.json.JSON

/**
  * Created by xiaoyuan on 2017/11/27.
  */
object Json {
  def main(args: Array[String]): Unit = {
    var str="{\"code\":\"200\",\"data\":[{\"time\":\"20171119220400\",\"traffic\":1556756665280},{\"time\":\"20171119120500\",\"traffic\":2225016248102}]}";
    var source = JSON.parseFull(str).asInstanceOf[Some[Map[String,Any]]];
    var list = source.get("data").asInstanceOf[List[Map[String, Any]]]
    list.map(x=>{
      println(x.get("time").get+"##" +x.get("traffic").get)
    })
    /*
    source match {
      case Some(map: Map[String, Any]) =>{
        println(map)
        println("###")
        println(map.get("data").get)
        var list = map.get("data").get.asInstanceOf[List[Map[String, Any]]]
        list.map(x=>{
          println(x.get("time").get+"##" +x.get("traffic").get)
        })

      }
      case None => println("Parsing failed")
      case other => println("Unknown data structure: " + other)
    }*/
  }
}
